home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / haeberli / objtools / sterrend.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  3KB  |  124 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  *    sterrend -
  19.  *        Render a object to be viewed with stereo glasses.
  20.  *
  21.  *                Paul Haeberli - 1989
  22.  */
  23. #include "gl.h"
  24. #include "device.h"
  25. #include "math.h"
  26. #include "sgiobj.h"
  27. #include "stdio.h"
  28.  
  29. #define XDELTA    (0.1)
  30. #define YDELTA    (0.0)
  31.  
  32. float fgetmousex();
  33. float fgetmousey();
  34.  
  35. float xrot, yrot;
  36. float tran, p;
  37. sgiobj* obj;
  38.  
  39. int drawworld();
  40.  
  41. main(argc,argv)
  42. int argc;
  43. char **argv;
  44. {
  45.     int i;
  46.     float param;
  47.     short val;
  48.     float xdelta;
  49.  
  50.     if(argc<2) {
  51.     fprintf(stderr,"usage: sterrend obj.sgo\n");
  52.     exit(1);
  53.     }
  54.     obj = readsgiobj(argv[1]);
  55.     if(!obj) {
  56.     fprintf(stderr, "sterrend: can't read %s\n",argv[1]);
  57.     exit(1);
  58.     }
  59.     p = 0.0;
  60.     xrot = yrot = 0;
  61.     tran = -5.0;
  62.     keepaspect(5,4);
  63.     winopen("sterrend");
  64.     RGBmode();
  65.     doublebuffer();
  66.     gconfig();
  67.     RGBcolor(128,128,128);
  68.     clear();
  69.     swapbuffers();
  70.     clear();
  71.     zbuffer(1);
  72.     backface(1);
  73.     matinit();
  74.     matrixinit();
  75.     renderperspective(250,5.0/4.0,0.1,100.0);
  76.     shadeinit();
  77.     qdevice(LEFTMOUSE);
  78.     qdevice(MIDDLEMOUSE);
  79.     xdelta = XDELTA;
  80.     while(1) {
  81.     if(getbutton(MIDDLEMOUSE))
  82.         xdelta = fgetmousex()/10.0;
  83.     else {
  84.         xrot = fgetmousex();
  85.         yrot = fgetmousey();
  86.     }
  87.     zclear();
  88.     RGBwritemask(0xff,0x00,0x00); 
  89.     accset(0.0,0.0,-xdelta,-YDELTA);
  90.     drawworld();
  91.     zclear();
  92.     RGBwritemask(0x00,0xff,0xff); 
  93.     accset(0.0,0.0,xdelta,-YDELTA);
  94.     drawworld();
  95.     swapbuffers();
  96.     while(qtest()) {
  97.         switch(qread(&val)) {
  98.         case REDRAW:
  99.             reshapeviewport();
  100.             break;
  101.         }
  102.     }
  103.     }
  104. }
  105.  
  106. drawworld()
  107. {
  108.     pushmatrix();
  109.     translate(0.0,0.0,tran);
  110.     rgb(0.05,0.05,0.05);
  111.     clear();
  112.     rot(360.0*xrot,'x');
  113.     rot(360.0*yrot,'y');
  114.     scale(2.0,2.0,2.0);
  115.     shadeon();
  116.     setdiffuse(0.5,0.5,0.5);
  117.     setspecular(0.7,0.7,0.7);
  118.     setshininess(20.0);
  119.     drawsgiobj(obj,DRAW_POINTS|DRAW_NORMALS); 
  120.     shadeoff();
  121.     popmatrix();
  122. }
  123.  
  124.